package br.ufmg.dcc.simulesspl.controller;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.junit.Test;

import br.ufmg.dcc.simulesspl.exception.InvalidSelectionException;
import br.ufmg.dcc.simulesspl.model.EngineerCard;
import br.ufmg.dcc.simulesspl.model.EngineerSelection;

public class EngineerSelectionControllerTest {

	@Test
	public void correctEngineerWillBeChosen() throws InvalidSelectionException {
		EngineerSelection engController = new EngineerSelection();

		List<EngineerCard> EngineerOptions = engController.getEngineerOptions();
		assertThat(EngineerOptions.size(), equalTo(3));

		engController.select("1");
		assertThat(engController.getSelectedDeveloper(), equalTo(EngineerOptions.get(0)));
		assertThat(engController.getSelectedBugFixer(), nullValue());

		engController.select("2 develop");
		assertThat(engController.getSelectedDeveloper(), equalTo(EngineerOptions.get(1)));
		assertThat(engController.getSelectedBugFixer(), nullValue());

		engController.select("3 bugfix");
		assertThat(engController.getSelectedDeveloper(), equalTo(null));
		assertThat(engController.getSelectedBugFixer(), equalTo(EngineerOptions.get(2)));
	}

	@Test(expected = Exception.class)
	public void zeroEngineerNumberWillThrowException() throws InvalidSelectionException {
		EngineerSelection psc = new EngineerSelection();
		psc.select("0");
	}

	@Test(expected = Exception.class)
	public void engineerNumberGreaterThan3WillThrowException() throws InvalidSelectionException {
		EngineerSelection psc = new EngineerSelection();
		psc.select("4");
	}

	@Test(expected = Exception.class)
	public void invalidCommandWillThrowException() throws InvalidSelectionException {
		EngineerSelection psc = new EngineerSelection();
		psc.select("2 wrongCommand");
	}

	@Test
	public void tokensAfterCommandWillBeIgnored() throws InvalidSelectionException {
		EngineerSelection psc = new EngineerSelection();
		psc.select("2 develop asd bla asdasd sdon32 4r2 fd");
	}

	@Test(expected = Exception.class)
	public void invalidIdWillFail() throws InvalidSelectionException {
		EngineerSelection psc = new EngineerSelection();
		psc.select("A develop");
	}

}
